package com.qk.management.controller;
import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.course.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Just、倾城
 * @created 2025-10-12
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;


   @GetMapping("/subject/{subject}")
   public Result listBySubject(@PathVariable String subject){
        List<Course> data = courseService.listBySubject(subject);
        return Result.success(data);
    }
    @GetMapping("/list")
    public Result list(){
        List< Course> data = courseService.listAll();
        return Result.success(data);
    }
    @PutMapping
    public Result update(@RequestBody Course course){
        courseService.update(course);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id) {
        log.info("查询课程id:{}",id);
        Course course = courseService.getById(id);
        return Result.success(course);
    }
    @PostMapping
    public Result add(@RequestBody Course course){
        courseService.add(course);
        return Result.success();
    }
    /**
     * 删除课程
     * @param
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        courseService.delete(id);
        return Result.success();
    }
    /**
     * 分页查询
     * @param courseDTO
     * @return
     */
    @GetMapping
    public Result page(CourseDTO courseDTO) {
        PageResult<Course> data = courseService.page(courseDTO);
        return Result.success(data);
    }
}
